package com.promote.algorithm;

/**
 * @ClassName RemoveElement
 * Description 移除目标元素
 * @Author LiZiHao
 * Date 2021/8/11 11:00
 * @Version 1.0
 **/
public class RemoveElement {

    public static int removeElement(int[] nums, int val) {

        int length = nums.length;
        int n = 0;

        for (int i = 0; i < length; i++) {

            if (nums[i] != val) {
                nums[n] = nums[i];
                n++;
            }
        }
        return n;
    }

    public static void main(String[] args) {
        int[] nums = {0,1,2,2,3,0,4,2};
        int removeElement = removeElement(nums, 2);

        System.out.println(removeElement);
    }
}
